package com.dennytech.tac.statistics;

import android.content.Context;

import com.dennytech.tac.utils.Log;

public class Stat {

	private static final String LOG_TAG = Stat.class.getSimpleName();

	private GoogleAnalyticsHandler gaHandler;

	private static Stat instance;

	public static void init(Context context) {
		if (instance == null) {
			instance = new Stat(context);
		}
	}

	public static void uninit() {
		if (instance == null) {
			Log.w(LOG_TAG, "Stat has not be init yet.");
			return;
		}

		instance.gaHandler.sendEmptyMessage(GoogleAnalyticsHandler.SESSION_END);
	}

	public Stat(Context context) {
		this.gaHandler = new GoogleAnalyticsHandler(context);
	}

	public static void event(String category, String action, String label,
			int value) {
		if (instance == null) {
			Log.w(LOG_TAG, "instance has not to be init");
			return;
		}

		instance.gaHandler.sendMessage(instance.gaHandler.obtainMessage(
				GoogleAnalyticsHandler.EVENT, new Object[] { category, action,
						label, value }));
	}

	public static void pageView(String pageName) {
		if (instance == null) {
			Log.w(LOG_TAG, "instance has not to be init");
			return;
		}

		instance.gaHandler.sendMessage(instance.gaHandler.obtainMessage(
				GoogleAnalyticsHandler.PAGE_VIEW, pageName));
	}
}
